<%-- 
    Document   : elegirProveedores
    Created on : 11-may-2012, 7:52:51
    Author     : Hermanos
--%>

<%@page import="com.comprainsumos.MPersistencia.MProveedor"%>
<%@page import="com.comprainsumos.modelo.Proveedor"%>
<%@page import="com.comprainsumos.modelo.Carrito"%>
<%@page import="java.util.Iterator"%>
<%@page import="com.comprainsumos.MPersistencia.MProductoProveedor"%>
<%@page import="java.util.LinkedList"%>
<%@page import="com.comprainsumos.modelo.InsumoProveedor"%>
<%@page import="java.util.List"%>
<%@page import="javax.swing.JOptionPane"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Eleccion de proveedores</title>
        <link href="css/aristo/jquery-wijmo.css" type="text/css" rel="stylesheet"/>
        <link href="css/wijmo/jquery.wijmo.wijsuperpanel.css" rel="stylesheet" type="text/css" />
        <link href="css/wijmo/jquery.wijmo.wijlist.css" rel="stylesheet" type="text/css" />
        <link href="css/wijmo/jquery.wijmo.wijtextbox.css" rel="stylesheet" type="text/css" />
        <link href="css/wijmo/jquery.wijmo.wijdropdown.css" rel="stylesheet" type="text/css" />
        <link href="css/wijmo/jquery.wijmo.wijradio.css" rel="stylesheet" type="text/css" />
        <link href="css/wijmo/jquery.wijmo.wijcheckbox.css" rel="stylesheet" type="text/css" />
        <script src="js/external/jquery-1.7.1.min.js" type="text/javascript"></script>
        <script src="js/external/jquery-ui-1.8.18.custom.min.js" type="text/javascript"></script>
        <script src="js/external/jquery.mousewheel.min.js" type="text/javascript"></script>
        <script src="js/external/jquery.bgiframe-2.1.3-pre.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijutil.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijsuperpanel.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijlist.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijdropdown.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijradio.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijcheckbox.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijtextbox.js" type="text/javascript"></script>
        <!-- Tabla-->
        <link href="css/wijmo/jquery.wijmo-open.2.0.8.css" rel="stylesheet" type="text/css" />
        <link href="css/wijmo/jquery.wijmo.wijpager.css" rel="stylesheet" type="text/css" />
        <link href="css/wijmo/jquery.wijmo.wijgrid.css" rel="stylesheet" type="text/css" />
        <script src="js/external/globalize.min.js" type="text/javascript"></script>
        <script src="js/external/jquery.wijmo-open.all.2.0.8.min.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijpager.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijdatasource.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijgrid.js" type="text/javascript"></script>
        <%
            List<Proveedor> prov = new LinkedList();
            prov = MProveedor.listar();
        %>
        <script id="scriptInit" type="text/javascript">
            $(document).ready(function () {
                veri = false;
                $(":input[type='text'],:input[type='password'],textarea").wijtextbox();
                $(":input[type='button'],:input[type='submit']").button();
                $(":input[type='checkbox']").wijcheckbox();
                $("#tabla").wijgrid({
                    selectionMode: "singleRow",
                    allowSorting: true,
                    allowPaging: true,
                    pageSize: 10,
                    data: [
            <%

                for (Iterator it = prov.iterator(); it.hasNext();) {
                    Proveedor pp = (Proveedor) it.next();

                    out.print("[" + pp.getNit() + ",'" + pp.getNombre() + "','" + pp.getEmail() + "']" + ",");
                }
            %>
                        ],
                        columns: [
                            { headerText: "Nit" }, { headerText: "Nombre" }, { headerText: "Email" }
                        ],
                    rowStyleFormatter: function (args) {
                        if ((args.state & $.wijmo.wijgrid.renderState.rendering) && (args.type & $.wijmo.wijgrid.rowType.data)) {
                            args.$rows
                            .css("cursor", "pointer")
                            .click(function (e) {
                                selectionChanged:  onSelectionChanged();
                            })
                        }
                    },
                   
                    selectionChanged: onSelectionChanged
                });
                function onSelectionChanged() {
                    if(veri == true){
                        var sc = $("#tabla").wijgrid("selection").selectedCells();
                        var cellInfo = sc.item(0);
                        elegirI(cellInfo.value().toString());
                    }else
                        veri = true
                }
                
                $("#cantidad").wijinputnumber(
                {
                    type: 'numeric',
                    minValue: 0,
                    maxValue: 999999,
                    decimalPlaces: 3,
                    showSpinner: true
                });
              
            });
            function elegirI(codins){
                location.href='gestionCompra.jsp?opmen=elegirI&nit='+codins;
            }
        </script>
    </head>
    <body>
        <div style="width: 30%;">
            <table rules="all" id="tabla">

            </table>
        </div>
        </br>
        <%
            /*    HttpSession sesion = request.getSession();
            String cant = request.getParameter("cantidad");
            double cantidad = 0;
            if (cant != null) {
            cantidad = Double.parseDouble(cant);
            }
            String select[] = request.getParameterValues("nit");
            if (select != null && select.length != 0) {
            
            
            List<Carrito> listaCarrito = (List<Carrito>) sesion.getAttribute("carrito");
            if (listaCarrito == null) {
            listaCarrito = new LinkedList<Carrito>();
            }
            for (int i = 0; i < select.length; i++) {
            Carrito c = new Carrito();
            c.setProductoP(MProductoProveedor.getInsumoProveedor("" + codins, select[i]));
            c.setCantidad(cantidad);
            listaCarrito.add(c);
            }
            
            session.setAttribute("carrito", listaCarrito);
            response.sendRedirect("gestionCompra.jsp?opmen=compra");
            }*/
        %>
    </body>
</html>
